import {lazy, ReactNode} from "react";
import {DashboardOutlined, UserOutlined} from "@ant-design/icons";

const Page404 = lazy(() => import("../pages/Page404"));
const Dashboard = lazy(()=>import("../pages/Dashboard")) ;
const Login = lazy(()=>import('../pages/Login')) // 懒加载 登录组件
const Users = lazy(()=>import('../pages/user/Users')) // 懒加载 登录组件
export interface IRouter{
    // 路由标题
    title: string
    // 路由路径
    path: string
    //是否精确匹配
    exact?:boolean,
    //图标
    icon?:ReactNode,
    // 路由组件
    component?: ReactNode
    // 子路由
    children?: IRouter[]
}

// 不用登录就可以显示的路由
const unAuthRouter: IRouter[] = [
    {
        path: '/login',
        title: '登录',
        component: <Login/>,
    },

    // 按照匹配规则,最后匹配不到会匹配404
    {
        path: '*',
        title: '404',
        component: <Page404/>,
    },
];
// 登录以后才能看到的路由
const authRouter: IRouter[] = [
    {
        path: '/admin/dashboard',
        title: '仪表盘',
        component: <Dashboard/>,
        icon: <DashboardOutlined/>,
    },
    {
        path: '/admin/users',
        title: '用户管理',
        icon: <UserOutlined/>,
        children:[
            {
                path: '/admin/users/list',
                title: '用户列表',
                component: <Users/>,
                icon: <UserOutlined/>,
            },
            {
                path: '/admin/dashboard1',
                title: '仪表盘',
                component: <Dashboard/>,
                icon: <DashboardOutlined/>,
            },
        ]
    },
]
export {authRouter, unAuthRouter};
